﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Aliyeye.Car.Net.UI.Components;

namespace Aliyeye.Car.Net.UI.OrderModel
{
    public partial class BillingDetailsList : Aliyeye.Car.Net.UI.BaseForm
    {
        private int reserveID = 0;

        public BillingDetailsList()
        {
            InitializeComponent();
        }

        public BillingDetailsList(int intResID)
        {
            InitializeComponent();
            this.reserveID = intResID;
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void BillingDetailsList_Load(object sender, EventArgs e)
        {
            this.pager1.PageCurrent = 1;
            this.pager1.Bind();
        }
        
        private int dgvBind()
        {
            string strWhere = "BillingDetails.IntoSectionID='" + this.reserveID + "'";
            PageData pageData = new PageData(this, pager1, overlay);
            pageData.TableName = "BillingDetails left join  Reserve  on BillingDetails.IntoSectionID=Reserve.Id left join Customer on BillingDetails.CustomerID=Customer.Id  left join Accounts_Users on BillingDetails.InputUserID=Accounts_Users.UserID";
            pageData.PrimaryKey = "BillingDetails.BillingDetailsID";
            pageData.OrderStr = "BillingDetails.BillingDetailsID desc";
            pageData.PageIndex = this.pager1.PageCurrent;
            pageData.PageSize = this.pager1.PageSize;
            pageData.QueryCondition =  strWhere.ToString();
            pageData.QueryFieldName = "BillingDetails.*  ,Reserve.Code, Customer.Code as CustomerCode,Customer.Name, Accounts_Users.TrueName";

            DataSet ds = pageData.QueryDataTable();
            dgvInfo.AutoGenerateColumns = false;
            dgvInfo.DataSource = this.pager1.bindingSource;
            return pageData.TotalCount;
        }

        private int pager1_EventPaging(EventPagingArg e)
        {
            return dgvBind();
        }

        private void dgvInfo_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            if (this.dgvInfo.Rows.Count != 0)
            {
                for (int i = 0; i < this.dgvInfo.Rows.Count; )
                {
                    this.dgvInfo.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.PapayaWhip;
                    i += 2;
                }
            }
        }

        private void dgvInfo_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            e.CellStyle.WrapMode = DataGridViewTriState.True;
            if (this.dgvInfo.Columns[e.ColumnIndex].Name == "入款日期" || this.dgvInfo.Columns[e.ColumnIndex].Name == "顺延还车日期")
            {
                if (e.Value != null)
                {
                    e.Value = Convert.ToDateTime(e.Value.ToString().Trim()).ToString("yyyy-MM-dd HH:mm:ss");
                }
            }
        }


    }
}
